﻿using System;
using System.Collections.Generic;
using System.Text;

namespace NetCoreClass
{
    public class UploadImage
    {
        /// <summary>
        /// 向图片服务器传送图片
        /// </summary>
        /// <param name="Url">图片服务器路径</param>
        /// <param name="token">传送秘钥</param>
        /// <param name="filePath">本地文件路径</param>
        /// <param name="savePath">上传目录</param>
        /// <returns></returns>
        public static string upload(string Url,string token, string filePath, string savePath)
        {
            WebHttp webhttp = new WebHttp();
            List<ListParams> files = new List<ListParams>();
            files.Add(new ListParams("media", filePath));//文件 
            List<ListParams> paras = new List<ListParams>();
            paras.Add(new ListParams("type", "image"));
            paras.Add(new ListParams("path", savePath));//上传根路径
            string timestamp = Time.GetTimeStamp().ToString();//一定要转换字符串
            paras.Add(new ListParams("timestamp", timestamp));
            DESEncryptor des = new DESEncryptor();
         
            string sign = des.md5(token + timestamp + "image" + savePath, "utf-8");
            paras.Add(new ListParams("sign", sign));

            string imgurl = Url + "Upload/UploadImage";

            return webhttp.WebRequestPostFile(imgurl, paras, files);
        }
    }
}
